import moment from 'moment';

let dates = [];
let responsePer = [];
let responseTime = [];

const range = [80, 100];
const range2 = [500, 1000];

for (let i = 0; i <= 7 * 24; i++) {
    const value = (Math.random() * (range[1] - range[0]) + range[0]).toFixed(2);
    const value2 = (Math.random() * (range2[1] - range2[0]) + range2[0]).toFixed(2);
    dates.push(moment().subtract(7 * 24 - i, 'hour').format('YYYY-MM-DD HH:mm:SS'));
    responsePer.push(value);
    responseTime.push(value2);
}

export const responseOption = {
    color: ['#348EED', '#FBDF90'],
    legend: {
        data: ['响应时间', '响应成功率'],
        x: 'center'
    },
    title: {
        text: '响应情况'
    },
    tooltip: {
        trigger: 'axis'
    },
    toolbox: {
        feature: {
            saveAsImage: { name: 'DHCP', title: '保存' }
        }
    },
    dataZoom: [
        {
            show: true,
            realtime: true,
        }
    ],
    grid: {
        top: '20%',
        left: 60,
        right: 60,
        height: '65%'
    },
    xAxis: [
        {
            type: 'category',
            show: false,
            data: dates
        }
    ],
    yAxis: [
        {
            name: '响应时间(ms)',
            nameLocation: 'start',
            inverse: true,
            type: 'value',
        },
        {
            name: '响应成功率(%)',
            type: 'value',
        },
    ],
    series: [
        {
            name: '响应时间',
            type: 'line',
            yAxisIndex: 0,
            data: responseTime
        },
        {
            name: '响应成功率',
            type: 'line',
            yAxisIndex: 1,
            data: responsePer
        }
    ]
};
